<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${title }</title>
    <link rel="stylesheet" href="${basePath}/static/bootstrap/css/bootstrap.css"/>
    <link href="${basePath}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/login.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
<%--     <link rel="stylesheet" href="${basePath}/static/css/content_leftNav.css"/>
    <link rel="stylesheet" href="${basePath}/static/css/FrontControl.css"/> --%>
    <script  type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
	<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
    <script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
    <link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">
    
</head>
<body>
<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<!--内容部分-->
<div class="list_main lay_out" class="clearfix">
    <div class="list_DH">
        <%@include file="/WEB-INF/templates/common/medBorrowNav.jsp"%>
    </div>
    <div class="list_NR">
        <div class="loc">
            <h3 style="margin:0">借阅统计</h3>
        </div>
        <div class="list_con_table">
            <div class="search_table">
                <ul class="clearfix" style="margin-bottom:0;">
				    <li class="Label_1" style="width:10%">ID号：&nbsp;</li>
				    <li class="Label_2" style="width:16%"><input class="input_box" style="width:80%" type="text" id='mrId'/></li>
                	
                	<li class="Label_1" style="width:10%">出院日期：&nbsp;</li>
                    <li class="Label_4" style="text-align:center;width:27%">
                    	<input class="input_box" style="width:40%;" type="text" id='outHospitalStartDate' onFocus="WdatePicker()" />
                    	<span>&nbsp;-&nbsp;</span>
                    	<input class="input_box" type="text" style="width:40%;" id='outHospitalEndDate' onFocus="WdatePicker()" /></li>
                    <li class="Label_1" style="width:10%">借阅日期：&nbsp;</li>
                    <li class="Label_4" style="width:27%;text-align:center;">
                    	<input class="input_box" style="width:40%;" type="text" id='checkStartTime' onFocus="WdatePicker()" />
                    	<span>&nbsp;-&nbsp;</span>
                    	<input class="input_box" type="text" style="width:40%;" id='checkEndTime' onFocus="WdatePicker()" /></li>
                    <li class="Label_5">
                        <div class="right" style="text-align:right">
                            <a onclick="searchQua()">查询</a>
                        </div>
                    </li>
                  
                </ul>
            </div> 
             <table class="Search_tableList" cellpadding="0" cellspacing="0">
                <tr>
             
                    <td class="tdLabel_4">ID号</td>
                    <td class="tdLabel_4">姓名</td>
                    <td class="tdLabel_4">出院时间</td>
                    <td class="tdLabel_4">借阅人</td>
                    <td class="tdLabel_4">借阅时间</td>
                    <td class="tdLabel_4">审批人</td>
                </tr>
                <tr id="loading" style="height:50px;display:none">
	                 <td colspan="6" align="center" ><img src="${basePath}/static/layer/skin/default/loading-2.gif"></td>
	            </tr>
                <tbody id="tbody">
                </tbody>
            </table>
        </div>
        <div class="pageList">
            <ul class="pagination clearfix" id="page_plus"></ul>
            <div class="pagination">
                <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
            </div>
        </div> 
    </div>
</div>
<!------页脚部分--------->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>

<!--JS部分-->
<script type="text/javascript">
	function exportBorrowStaitcsToExcel(){
		var mrId=$("#mrId").val();
		var outHospitalStartDate=$("#outHospitalStartDate").val();
		var outHospitalEndDate=$("#outHospitalEndDate").val();
		var checkStartDate=$("#checkStartTime").val();
		var checkEndDate=$("#checkEndTime").val();
		if((outHospitalStartDate==null || outHospitalStartDate=="") && (outHospitalEndDate==null || outHospitalEndDate=='') 
				&& (mrId==null || mrId=='') && (outOfficeName==null || outOfficeName=='') && (checkStartDate==null || checkStartDate=='')&& (checkEndDate==null || checkEndDate=='')){
			layer.alert("请输入导出条件!",{icon:7});
			return;
		}

		$.ajax({
			type:"get",
			url:"${basePath}/borrow/selectApplyBorrowByKeywords",
			data:{mrId:mrId,outHospitalStartDate:outHospitalStartDate,outHospitalEndDate:outHospitalEndDate,
				outOfficeName:outOfficeName,applyBorrowStartTime:checkStartDate,applyBorrowEndTime:checkEndDate},
			success:function(data){
				if(data.success){
					location.href="${basePath}/borrow/exportBorrowStaitcsToExcel?mrId="+mrId+
					"&applyBorrowStartTime="+checkStartDate+"&outOfficeName="+outOfficeName+"&applyBorrowEndTime="+checkEndDate+
					"&outHospitalStartDate="+outHospitalStartDate+"&outHospitalEndDate="+outHospitalEndDate+"&name="+name+"";
				}else{
					layer.alert(data.msg,{icon:5});
				}
			}
		})
	}
	
	function searchQua(){
		queryQua(1,10);
	}

	function queryQua(currentStartNum,pageSize){
		
		var mrId=$("#mrId").val();
		var outOfficeName=$("#outOfficeName").val();
		var outHospitalStartDate=$("#outHospitalStartDate").val();
		var outHospitalEndDate=$("#outHospitalEndDate").val();
		
		var checkStartDate=$("#checkStartTime").val();
		var checkEndDate=$("#checkEndTime").val();
		
		
		if((outHospitalStartDate==null || outHospitalStartDate=="") && (outHospitalEndDate==null || outHospitalEndDate=='') 
				&& (mrId==null || mrId=='') && (outOfficeName==null || outOfficeName=='') && (checkStartDate==null || checkStartDate=='')&& (checkEndDate==null || checkEndDate=='')){
			layer.alert("请输入查询条件!",{icon:7});
			return;
		}
		

		$.ajax({
			type:"get",
			url:"${basePath}/borrow/selectApplyBorrowByKeywords",
			data:{mrId:mrId,outHospitalStartDate:outHospitalStartDate,outHospitalEndDate:outHospitalEndDate,
				outOfficeName:outOfficeName,applyBorrowStartTime:checkStartDate,applyBorrowEndTime:checkEndDate,pageNo:currentStartNum,pageSize:pageSize},
			beforeSend:function(){
					$("#tbody").html("");
					$("#loading").show();
			},
			success:function(data){
				$("#loading").hide();
				console.log(data);
				if(data.success){
					var borrowRecords=data.data.borrowRecordList;
					var totalCounts=data.data.totalCount;
					var html="";
					if(borrowRecords.length!=0){
						for(var i=0;i<borrowRecords.length;i++){
							var borrowRecord=borrowRecords[i];
							html+=" <tr>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.mrId==undefined?'':borrowRecord.mrId)+"</td>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.NAME==undefined?'':borrowRecord.NAME)+"</td>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.outHospitalDate==undefined?'':borrowRecord.outHospitalDate)+"</td>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.borrowMan==undefined?'':borrowRecord.borrowMan)+"</td>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.borrowTime==undefined?'':borrowRecord.borrowTime)+"</td>"+
					              "      <td class='tdLabel_5'>"+(borrowRecord.checkMan==undefined?'':borrowRecord.checkMan)+"</td>"+
					              "  </tr>";
						}
						
						$("#tbody").html("").html(html);	
						page(currentStartNum,totalCounts,pageSize);
					}
                 }else{
					layer.alert(data.msg,{icon:5});
					$("#tbody").html("");
					$("#totalPage").html(0);
		            $("#currentPage").html(0+"/"+0);
		            $('#page_plus').html("");
				}
	
			}
		})
		
	}
	
	 function page(currentPage,totalCounts,pageSize){
	
	        var visiblePages = 10;
	         //var totalPages = totalCounts%pageSize==0?(totalCounts/pageSize):(parseInt(totalCounts/pageSize)+1);
	          var totalPages = Math.ceil(totalCounts/pageSize);
	        $('#page_plus').jqPaginator({

	            totalCounts: totalCounts,
	            pageSize:pageSize,
	            visiblePages: visiblePages,
	            currentPage: currentPage,

	            first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	            prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	            last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	            onPageChange: function (num,type) {
	          
	            	 if(type !='init'){
	                 
	            		 queryQua(num,pageSize);
	                 }
	            	
	                $("#totalPage").html(totalCounts);
	                $("#currentPage").html(num+"/"+totalPages);
	            }
	        });

	    }
	 
	
</script>

</body>
</html>